<template>
  <div class="addBills">
    <el-form
      ref="ruleForm"
      :model="ruleForm"
      :rules="rules"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="姓名" prop="user">
        <el-input v-model="ruleForm.user" />
      </el-form-item>

      <el-form-item label="住址" prop="house">
        <el-select v-model="ruleForm.house" placeholder="请选择住址">
          <el-option label="区域一" value="shanghai" />
          <el-option label="区域二" value="beijing" />
        </el-select>
      </el-form-item>

      <el-form-item label="月份" prop="time">
        <el-date-picker v-model="time" type="month" placeholder="选择月份" />
      </el-form-item>

      <el-form-item label="费用" prop="money" />

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即提交</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        user: '',
        house: '',
        time: '',
        money: ''

      },
      rules: {
        user: [
          { required: true, message: '请输入姓名', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        house: [{ required: true, message: '请选择住址', trigger: 'change' }],
        time: [
          {
            type: 'date',
            required: true,
            message: '请选择月份',
            trigger: 'change'
          }
        ]
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.addBills {
  margin-top: 30px;
}
</style>
